package com.ytktt.study.week5.task2.naming.parser;

import com.ytktt.study.week5.task2.naming.component.Student;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

/**
 * 自定义Bean转换器
 *
 * @author ytk
 */
public class StudentBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {

    @Override
    protected Class<?> getBeanClass(Element element) {
        return Student.class;
    }

    @Override
    protected void doParse(Element element, BeanDefinitionBuilder bean) {
        String code = element.getAttribute("code");
        if (StringUtils.hasText(code)) {
            bean.addPropertyValue("code", code);
        }

        String name = element.getAttribute("name");
        if (StringUtils.hasText(name)) {
            bean.addPropertyValue("name", name);
        }
    }

}
